home *** CD-ROM | disk | FTP | other *** search
/ McDisk 1 / McDisk 1.adf / sources / Interger_root.S < prev    next >
Text File  |  1978-04-12  |  1KB  |  51 lines

  1.  
  2. ; This is a super-mega-fast routine to extract the square root
  3. ; of an integer number.
  4. ;  
  5. ; At the moment the routine calculates with 16 bits.
  6. ; To calculate with 32 bits, simply change all instructions to long
  7. ; and replace the `move.w #$4000,d2` with `move.l #$40000000,d2`.
  8. ;
  9. ; This program is based on an article by OTTO PETER, Innsbruck
  10. ; and translated into MC68000 assembler by MISSION of COMA.
  11. ;
  12. ; If you are interested in the development of this algorithm,
  13. ; go into a library and search for c`t 1/1990, page 300-306.
  14. ; You will find there a nice version of the routine which
  15. ; calculates the square root for the 32-bit-IEEE-single-precision-format
  16.  
  17.  
  18. ROOT:
  19.  
  20. ;    SETTINGS IN:      D0.w   -   number
  21. ;
  22. ;        OUT:      D0.w   -   result
  23. ;                                -   sign- and zeroflag are valid
  24.  
  25. movem.w    d1-d3,-(sp)
  26. move.w    #$4000,d2
  27.  
  28. root_loop:
  29. move.w    d1,d3
  30. add.w    d2,d3
  31.  
  32. lsr.w    #1,d1
  33. cmp.w    d3,d0
  34. ble.s    boing
  35. sub.w    d3,d0
  36. or.w    d2,d1
  37.  
  38. boing:
  39. lsr.w    #2,d2
  40. bne.s    root_loop
  41.  
  42. cmp.w    d1,d0
  43. blt.s    no_round_up
  44. addq.w    #1,d1
  45.  
  46. no_round_up:
  47. move.w    d1,d0
  48. movem.w    (sp)+,d1-d3
  49. rts
  50.  
  51.